﻿/*s设置字体的大小*/
/*;(function(){
	function change(){
		var font = document.documentElement.clientWidth/375*50;
		document.documentElement.style.fontSize=font+'px';
	};
	window.addEventListener('resize',change,false);
	change();
})();*/
//设置常量
var Class = function () {
    var AJAXURL = 'http://mobile.zjpxny.com/';
    //var AJAXURL = 'http://localhost:8080';
    return function () {
        this.getAJAXURL = function () {
            return AJAXURL;
        }
    }
}();
//获取ajaxurl
var obj = new Class();
var ajaxUrl = obj.getAJAXURL();
document.title = '品行惠';

//alert(document.title);
//获取memberId;
var memberId = '';

if (sessionStorage.getItem('memberId') == null || sessionStorage.getItem('memberId') == 'null') {
    sessionStorage.setItem('memberId', getUrlParam('memberId'));
    memberId = getUrlParam('memberId');

    //memberId='1122';
} else {
    memberId = sessionStorage.getItem('memberId');
    //memberId='1122';
}
if (memberId == null || memberId == 0) {
   // localStorage.setItem('memberId',null);
    memberId = localStorage.getItem('memberId');
}
//alert(localStorage.getItem('memberId'));
if (memberId == null || memberId == 0||memberId=="") {
    window.location.href = 'authorizationPage.html';
}
    //
    // if(memberId!=null){
    //     $.ajax({
    //         type: "post",
    //         url: ajaxUrl + "mobile/member/getMember",
    //         async: true,
    //         data: {'memberId': memberId},
    //         success: function (data) {
    //            var result = data.result;
    //            if (result.openId==null){
    //                window.location.href = 'authorizationPage.html';
    //            }
    //         }
    //     });
    // }

cartNum();
//alertMsg(memberId);
//获取url中的参数方法
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}

//正则替换
function regChange(str, oldS, newS) {
    var reg = new RegExp("(^|&)" + oldS + "=([^&]*)(&|$)");
    var r = str.match(reg);
    console.log(str, r)
    var newStrs = r[0].replace(r[2], newS);
    var newResult = str.replace(r[0], newStrs);
    console.log(newResult);
    return newResult;
}

function errorTip() {
    layer.open({
        content: '网络延时',
        skin: 'msg',
        time: 2
    });
}

function programErrorTip() {
    layer.open({
        content: '程序出问题啦',
        skin: 'msg',
        time: 2
    });
}

function alertMsg(strS) {
    layer.open({
        content: strS,
        skin: 'msg',
        time: 2
    });
}

/*//导航的返回按钮
$('.detail-header').on('tap click','.return',function(){
	window.history.go(-1);
});*/

// 转为unicode 编码  
function encodeUnicode(str) {
    var res = [];
    for (var i = 0; i < str.length; i++) {
        res[i] = ("00" + str.charCodeAt(i).toString(16)).slice(-4);
    }
    return "\\u" + res.join("\\u");
}

// 解码  
function decodeUnicode(str) {
    str = str.replace(/\\/g, "%");
    return unescape(str);
}

//点击跳转到商品详情页面
function goToProDetails(obj) {
    if (obj.data("type") != 2) {
        window.location = 'proDetail.html?type=' + obj.data("type") + '&limitId=&id=' + obj.data('id');
    } else {
        window.location = 'proDetails-xs.html?type=' + obj.data("type") + '&limitId=' + obj.data('limit') + '&id=' + obj.data('id');
    }
}

function cartNum() {
    $.ajax({
        type: "post",
        url: ajaxUrl + '/mobile/member/cartNum',
        async: true,
        //productId=412&memberId=623&normalId=508&num=1
        data: {'memberId': memberId},
        success: function (data) {

            console.log(data)
            //            $("#cartShowNum").append("<div class=\"num\">111</div>");
            if (data.result.num > 0) {

                var html='<div class="num">'+data.result.num+'</div>';
             //   html+='<div class="num">'+4+'</div>';
                $("#cartShowNum").append(html);
            }
        }
    });
}

//cartNum()